#include "snake.h"
#include "share.h"
#include <windows.h>
#include <thread>
#include <mutex>


std::mutex mtx;

void keyboardControl(){
    while(gameRunning){
        std::lock_guard<std::mutex> lock(mtx);
        switch (mode_now)
        {
            case 1:
                handleInput();
                Sleep(50);
                if(GetAsyncKeyState(VK_ESCAPE) & 0x8000)
                {
                    mode_now = 3;
                }
                break;
            
            case 2:
                if(GetAsyncKeyState(VK_SPACE) & 0x8000)
                {
                    mode_now = 3;
                }
                break;
            case 3:
                if(GetAsyncKeyState(0x31) & 0x8000)
                {
                    mode_now = 1;
                }
                else if(GetAsyncKeyState(0x32) & 0x8000)
                {
                    mode_now = 2;
                }
                else if(GetAsyncKeyState(0x33) & 0x8000)
                {
                    mode_now = 5;
                }
                else if(GetAsyncKeyState(0x44) & 0x8000)
                {
                   exit(0); 
                }
                break;
            case 4:
                if(GetAsyncKeyState(0x31) & 0x8000)
                {
                    Sleep(50);
                    mode_now = 1;
                }
                else if(GetAsyncKeyState(0x32) & 0x8000)
                {   
                    Sleep(100);
                    mode_now = 3;
                }
                else
                {
                    
                }
                break;
            case 5:
                if(GetAsyncKeyState(VK_SPACE) & 0x8000)
                {
                    Sleep(100);
                    mode_now = 3;
                }
                break;
            default:
                break;
        }
        // std::this_thread::sleep_for(std::chrono::milliseconds(10));
    }
}